package com.liusy.code.templates;

import com.liusy.code.bean.*;
import java.util.List;

public class ModelTemplate
{
  protected static String nl;
  public static synchronized ModelTemplate create(String lineSeparator)
  {
    nl = lineSeparator;
    ModelTemplate result = new ModelTemplate();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "package ";
  protected final String TEXT_2 = ";" + NL + "" + NL + "import java.io.Serializable;" + NL + "import java.util.Date;" + NL + "" + NL + "import javax.persistence.Column;" + NL + "import javax.persistence.Entity;" + NL + "import javax.persistence.GeneratedValue;" + NL + "import javax.persistence.Id;" + NL + "import javax.persistence.Table;" + NL + "" + NL + "import org.hibernate.annotations.GenericGenerator;" + NL + "" + NL + "" + NL + "/**" + NL + " * " + NL + " **/" + NL + "@Entity" + NL + "@Table(name = \"";
  protected final String TEXT_3 = "\")" + NL + "public class ";
  protected final String TEXT_4 = " implements Serializable {" + NL + "" + NL + "\t        ";
  protected final String TEXT_5 = NL + "\t@Id" + NL + "\t@GeneratedValue(generator = \"system-uuid\")" + NL + "\t@GenericGenerator(name = \"system-uuid\", strategy = \"uuid\")" + NL + "\t@Column(name = \"ID\", unique = true, nullable = false)" + NL + "\tprivate ";
  protected final String TEXT_6 = " ";
  protected final String TEXT_7 = ";//";
  protected final String TEXT_8 = NL + "\t\t\t\t\t";
  protected final String TEXT_9 = NL + "\t@Column(name = \"";
  protected final String TEXT_10 = "\")" + NL + "\tprivate ";
  protected final String TEXT_11 = " ";
  protected final String TEXT_12 = ";//";
  protected final String TEXT_13 = NL + "\t\t\t";
  protected final String TEXT_14 = NL + NL + "\t" + NL + "\t" + NL + "\t" + NL + "\t\t    ";
  protected final String TEXT_15 = NL + "\tpublic ";
  protected final String TEXT_16 = " get";
  protected final String TEXT_17 = "() {" + NL + "\t\treturn this.";
  protected final String TEXT_18 = ";" + NL + "\t}" + NL + "\t" + NL + "\tpublic void set";
  protected final String TEXT_19 = "(";
  protected final String TEXT_20 = " ";
  protected final String TEXT_21 = ") {" + NL + "\t\tthis.";
  protected final String TEXT_22 = " = ";
  protected final String TEXT_23 = ";" + NL + "\t}" + NL + "\t\t\t";
  protected final String TEXT_24 = NL + "\t\t\t" + NL + "}";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    
	JavaTemplateArgs args = (JavaTemplateArgs)argument;
	
	
	String modeName = args.getModeName();
	String packageName = args.getPackageName();
	String className = args.getClassName();
	String tableName = args.getTableName();
	
	
	List<ColumnInfo> columnInfoList = args.getColumnInfoList();
	
	
	String entityPackageName = args.getPackageNameInfo().getEntityPackageName();
	String daoPackageName = args.getPackageNameInfo().getDaoPackageName();
	String servicePackageName = args.getPackageNameInfo().getServicPackageName();
	String actionPackageName = args.getPackageNameInfo().getActionPackageName();
	
	String entityClassName = args.getClassNameInfo().getEntityClassName();
	String daoClassName = args.getClassNameInfo().getDaoClassName();
	String serviceClassName = args.getClassNameInfo().getServicClassName();
	String actionClassName = args.getClassNameInfo().getActionClassName();
	
	String entityObjectName = args.getClassNameInfo().getEntityObjectName();
	String daoObjectName = args.getClassNameInfo().getDaoObjectName();
	String serviceObjectName = args.getClassNameInfo().getServicObjectName();
	String actionObjectName = args.getClassNameInfo().getActionObjectName();

    stringBuffer.append(TEXT_1);
    stringBuffer.append(entityPackageName);
    stringBuffer.append(TEXT_2);
    stringBuffer.append(tableName);
    stringBuffer.append(TEXT_3);
    stringBuffer.append(entityClassName);
    stringBuffer.append(TEXT_4);
    
			for(ColumnInfo columnInfo : columnInfoList)
			{
				if(columnInfo.getNameClassl().equals("id"))
				{
					
    stringBuffer.append(TEXT_5);
    stringBuffer.append(columnInfo.getJavaType());
    stringBuffer.append(TEXT_6);
    stringBuffer.append(columnInfo.getNameClassl());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(columnInfo.getRemark());
    stringBuffer.append(TEXT_8);
    
					continue;
				}
			
    stringBuffer.append(TEXT_9);
    stringBuffer.append(columnInfo.getNameDb());
    stringBuffer.append(TEXT_10);
    stringBuffer.append(columnInfo.getJavaType());
    stringBuffer.append(TEXT_11);
    stringBuffer.append(columnInfo.getNameClassl());
    stringBuffer.append(TEXT_12);
    stringBuffer.append(columnInfo.getRemark());
    stringBuffer.append(TEXT_13);
    		
			}
			
    stringBuffer.append(TEXT_14);
    
			for(ColumnInfo columnInfo : columnInfoList)
			{
			
    stringBuffer.append(TEXT_15);
    stringBuffer.append(columnInfo.getJavaType());
    stringBuffer.append(TEXT_16);
    stringBuffer.append(columnInfo.getNameClassu());
    stringBuffer.append(TEXT_17);
    stringBuffer.append(columnInfo.getNameClassl());
    stringBuffer.append(TEXT_18);
    stringBuffer.append(columnInfo.getNameClassu());
    stringBuffer.append(TEXT_19);
    stringBuffer.append(columnInfo.getJavaType());
    stringBuffer.append(TEXT_20);
    stringBuffer.append(columnInfo.getNameClassl());
    stringBuffer.append(TEXT_21);
    stringBuffer.append(columnInfo.getNameClassl());
    stringBuffer.append(TEXT_22);
    stringBuffer.append(columnInfo.getNameClassl());
    stringBuffer.append(TEXT_23);
    		
			}
			
    stringBuffer.append(TEXT_24);
    return stringBuffer.toString();
  }
}
